import Vue 			from 'vue'
import util 		from '../../util'
import axios 		from 'axios'
import { Toast,Dialog } 	from 'vant';
Vue.use(Toast,Dialog);

let amountWatch,moneyWatch;		//输入框监听器
let amountTimer,moneyTimer;		//输入框节流


export default {
	name: 'index',
	data(){
		return {
			overlay:false,		//弹窗是否显示遮罩层
			tradeStatus:1,		//1:我要买   2:我要卖
			list:[],			//后台配置列表
			realName:'',		//0:未认证  1:审核中  2:审核通过   3:审核驳回
			amount:'',			//购买数量
			amountOfMoney:'',	//购买金额
			listItem:{balance:0},		//当前选中币种情况
			token:'',			//当前用户token
			amountF:false,		//数量输入框是否获取焦点
			moneyF:false,		//价格输入框是否获取焦点
			p1:'请输入数量',		//placeholer1
			p2:'请输入金额',		//placeholer2
			isInUsdt:false,		//USDT是否显示首冲赠送提示
			uiEdit:0,			//是否个性化首页配置
			haveUnpaiedInmoneyOrder:false,	//是否有未完成订单
			uploadTimes:0,		//重复提交次数
			showService:false,	//是显示客服微信弹窗
			serverNumber:'myotcservice07',//客服号
			BTCFocus:false,		//首次定位在BTC上
		}
	},
	computed:{
		isAndroid(){
			//是否安卓
			return !util.client()
		},
		isIphoneX(){
			return util.isIphoneX()
		},
		isIphone(){
			return util.client()
		},
		isMYKEY(){
			return util.isMYKEY()
		}
	},
	beforeRouteLeave(to,from,next){
		if(to.name == 'goRealName'){
			//白名单，认证页可以直接跳
			next();
			return
		}
		util.waitSDKReady().then(token => {
			if(token && token.indexOf('失败') == -1){
				this.token = token;
				//登录成功后检测实名认证信息
				this.getRealNameStatus().then(() => {
					this.checkIsRealName().then(() => {
						next();
					},() => {
						//未实名认证或认证异常
						this.isRealName()
					})
				}).catch(err => {
					Toast('获取实名认证信息失败')
				})
			}else{
				Toast(token)
			}
		})
	},
	methods:{
		getRealNameStatus(){
			//特殊情况，再拿用户认证情况
			return new Promise((resolve,reject) => {
				if(this.realName === 2){
					resolve('');
					return
				}
				Toast.loading({
		            message: '检测实名认证状态',
		            duration:0,
		            forbidClick: true
		        })
				util.fetch(util.ajaxUrl()+`/site/mykey-otc-config`,{
					token:this.token || util.getToken(),
				}).then(res => {
					Toast.clear();
					if(res.retCode === 0){
						this.realName = res.retData.kyc_status;
						this.isInUsdt = res.retData.isInUsdt;
						resolve('')
					}else{
						reject('')
					}
				})
			})
		},
		calcMoney(amount){
			//根据币个数计算价格
			if(typeof amount != 'number') amount = +amount;
			let _amountOfMoney = isNaN(amount)?'':util.accMul(amount,this.listItem.exchange);
			if(_amountOfMoney) _amountOfMoney = _amountOfMoney.toFixed(2);
			this.amountOfMoney = _amountOfMoney?_amountOfMoney:'';
		},
		amountFocus(){
			this.p1 = '';
			this.amountF = true;
			if(typeof amountWatch === 'function') amountWatch();
			if(typeof moneyWatch === 'function') moneyWatch();
			amountWatch = this.$watch('amount',function(newVal,oldVal){
				if(newVal != oldVal){
					// if(this.amount < this.listItem.floor || this.amount > this.listItem.ceil){
					// 	Toast(`最低下单${this.listItem.floor+this.listItem.name}，最高下单${this.listItem.ceil+this.listItem.name}`);
					// 	return
					// }
					if(Number(newVal) < 0 || (newVal && newVal.indexOf('-') > -1)){
						this.amount = 0;
						return
					}
					//最多只能保持4位小数，USDT最多保持2位
					if(newVal && newVal.indexOf('.') > -1){
						let arrNewVal = newVal.split('.');
						let maxLen = this.listItem.name == 'USDT'?2:4;
						if(arrNewVal.length > 0 && arrNewVal[1].length > maxLen){
							arrNewVal[1] = arrNewVal[1].substr(0,maxLen);
							this.amount = arrNewVal.join('.');
							newVal = this.amount;
						}
					}
					this.calcMoney(newVal);
				}
				if(this.uiEdit == 2){
					console.log('ppp')
					this.getPrice(1,this.listItem.floor)
				}
			})
		},
		amountBlur(){
			this.p1 = '请输入数量';
			this.amountF = false;
			//输入框失焦时，重新拉取最新单价并计算价格
			if(typeof amountWatch === 'function') amountWatch();
			if(typeof moneyWatch === 'function') moneyWatch();
			if(this.amount) this.getPrice(1);
			let scrolltopTemp = document.documentElement.scrollTop || document.body.scrollTop;
			if(!this.isMYKEY) {
				setTimeout(()=>{
					if(!this.moneyF) window.scrollTo(0, 0);
				},100)
			}
		},
		calcAmount(money){
			//根据金额计算币种个数
			if(typeof money != 'number') money = +money;
			// if(money < this.listItem.minMoney) {
			// 	this.amount = '';
			// 	return
			// }
			// console.log(money)
			// console.log(money/this.listItem.exchange)
			// let _amount = util.accDiv(money,this.listItem.exchange);
			let _amount = money/this.listItem.exchange;
			//最多只能保持4位小数，USDT最多保持2位
			if(_amount && _amount.toString().indexOf('.') > -1){
				let arrNewVal = _amount.toString().split('.');
				let maxLen = this.listItem.name == 'USDT'?2:4;
				if(arrNewVal.length > 0 && arrNewVal[1].length > maxLen){
					arrNewVal[1] = arrNewVal[1].substr(0,maxLen);
					_amount = arrNewVal.join('.');
					// _amount = _amount.toFixed(maxLen);
				}
			}
			this.amount = _amount?_amount:'';
		},
		moneyFocus(){
			this.p2 = '';
			this.moneyF = true;
			if(typeof amountWatch === 'function') amountWatch();
			if(typeof moneyWatch === 'function') moneyWatch();
			moneyWatch = this.$watch('amountOfMoney',function(newVal,oldVal){
				if(newVal != oldVal){
					// if(this.amount < this.listItem.floor || this.amount > this.listItem.ceil){
					// 	Toast(`最低下单${this.listItem.floor+this.listItem.name}，最高下单${this.listItem.ceil+this.listItem.name}`);
					// 	return
					// }
					//最多只能保持两位小数
					if(newVal && newVal.indexOf('.') > -1){
						let arrNewVal = newVal.split('.');
						if(arrNewVal.length > 0 && arrNewVal[1].length > 2){
							arrNewVal[1] = arrNewVal[1].substr(0,2);
							this.amountOfMoney = arrNewVal.join('.');
							newVal = this.amountOfMoney;
						}
					}
					if(Number(newVal) < 0 || (newVal && newVal.indexOf('-') > -1)){
						this.amountOfMoney = 0;
						return
					}
					this.calcAmount(newVal)
				}
			})
		},
		moneyBlur(){
			this.p2 = '请输入金额';
			this.moneyF = false;
			if(typeof amountWatch === 'function') amountWatch();
			if(typeof moneyWatch === 'function') moneyWatch();
			//输入框失焦时，重新拉取最新单价并计算价格
			if(this.amountOfMoney) this.getPrice(1);
			let scrolltopTemp = document.documentElement.scrollTop || document.body.scrollTop;
			if(!this.isMYKEY){
				setTimeout(()=>{
					if(!this.amountF) window.scrollTo(0, 0);
				},100)
			}
		},
		next(){
			//点击购买或售出按钮跳转到下一页
			this.amount = +this.amount;
			if(this.amount < 0 || typeof this.amount != 'number' || isNaN(this.amount)) return
			if(this.amount >= this.listItem.floor && this.amount <= this.listItem.ceil){
				if(!util.getStorage('ETHAccount') && this.isMYKEY && this.listItem.name != 'EOS'){
					//在mykey中若是ETH，先检测是否已开通
					Toast('请先开通ETH区块链功能');
					setTimeout(() => {
                		if(window.MyKey && window.MyKey.Browser && window.MyKey.Browser.showOpenChain){
                			window.MyKey.Browser.showOpenChain('ETH');
                		}
                	},1000)
					return
				}
				if(this.tradeStatus === 1){
					//购买
					this.$router.push({
						path:'/buyType',
						query:{
							name:this.listItem.name,
							account:this.amount
						}
					})
				}else{
					//售出
					if(this.amount > this.listItem.balance){
						Toast(`可用余额仅为${this.listItem.balance}${this.listItem.name}`);
						return
					}
					this.$router.push({
						path:'/mykeySell',
						// path:'/sellType',
						query:{
							name:this.listItem.name,
							account:this.amount
						}
					})
				}
			}else if(this.amount < this.listItem.floor){
				Toast(`最低下单${this.listItem.floor+this.listItem.name}`);
			}else{
				Toast(`最高下单${this.listItem.ceil+this.listItem.name}`);
			}
		},
		init(refresh,special){
			//页面初始化
			if(!refresh) this.render(util.getStorage('otcConfig'),1);
			util.fetch(util.ajaxUrl()+`/site/mykey-otc-config`,{
				token:this.token || util.getToken(),
			}).then(res => {
				if(res.retCode === 0){
					if(special){
						this.realName = res.retData.kyc_status;
						this.isInUsdt = res.retData.isInUsdt;
						return
					}
					if(!refresh){
						this.render(res.retData,2);
						util.setStorage('otcConfig',res.retData);
						util.setStorage('token',(this.token || util.getToken()));
						if(this.uiEdit == 2){
							this.getPrice('',res.retData.currency.USDT.floor);
						}else{
							this.getPrice()
						}
					}else{
						//刷新状态
						this.realName = res.retData.kyc_status;
						this.isInUsdt = res.retData.isInUsdt;
						//刷新余额
						this.list.map(item => {
							item.balance = res.retData.currency[item.name].fund;
						})
					}
				}else{
					Toast(res.retMsg || '未知错误')
				}
			}).catch(error => {
				console.log(error)
			})
		},
		getPrice(state,tempAmount){
			//获取每个币单价
			// if((this.tradeStatus == 1 && this.amount >= this.listItem.floor && this.amount < this.listItem.ceil) || (this.tradeStatus == 2 && this.amount > 0)){
			if(this.amount >= this.listItem.floor && this.amount < this.listItem.ceil || tempAmount){
				let amount = tempAmount?(this.amount < tempAmount?tempAmount:this.amount):this.amount
				util.getPriceByName(this.listItem.name,this.tradeStatus,amount,'index').then(res => {
					// console.log(res)
					if(res.currency_id == this.listItem.name && res.type == this.tradeStatus) this.listItem.exchange = res.price;
					//计算最大购买金额，最小购买金额
					this.listItem.maxMoney = Number(util.accMul(this.listItem.ceil,res.price))
					this.listItem.minMoney = Number(util.accMul(this.listItem.floor,res.price))
					if(!this.amountF && !this.moneyF){
						console.log('计算价格1')
						if(this.amount) this.calcMoney(this.amount)
					}else if(this.amountF && !this.moneyF){
						console.log('计算价格2')
						//数量正在获取焦点中
						if(this.amount) this.calcMoney(this.amount)
					}else if(!this.amountF && this.moneyF){
						console.log('计算数量')
						//价格正在获取焦点
						if(this.amountOfMoney) this.calcAmount(this.amountOfMoney)
					}
				}).catch((err) => {
					Toast(err || '获取实时单价失败')
				})
			}
			if(!state){
				setTimeout(() => {
					this.getPrice();
				},util.time)
			}
		},
		render(retData,type){
			//渲染
			if(!retData) return
			if(typeof retData === 'string') retData = JSON.parse(retData)
			this.realName = retData.kyc_status;
			this.isInUsdt = retData.isInUsdt;
			this.haveUnpaiedInmoneyOrder = retData.haveUnpaiedInmoneyOrder;
			let [_currency,_list] = [retData.currency,[]];
			for(var i in _currency){
				let item = {
					icon:_currency[i].logo,
					name:_currency[i].name,
					selected:(!this.isMYKEY && _currency[i].name==='USDT')?true:false,
					exchange:0,
					desc:_currency[i].desc,
					ceil:+_currency[i].ceil,
					floor:+_currency[i].floor,
					balance:_currency[i].fund,
					minMoney:_currency[i].minMoney,
					maxMoney:_currency[i].maxMoney
				}
				if(this.uiEdit == 0 || ((this.uiEdit == 1 || this.uiEdit == 2) && _currency[i].name==='USDT')){
					//普通情况下 || 修改UI样式，只显示USDT
					_list.push(item)
				}
			}
			//默认选择
			if(_list.filter(item => item.selected).length == 0){
				if(this.isMYKEY){
					_list[0].selected = true;
				}else{
					if(_list.filter(item => item.name === 'USDT').length == 0){
						_list[0].selected = true;
					}
				}
			}
			//若URL参数中带有BTC，则默认选择BTC
			if(this.BTCFocus){
				_list.map(item => {
					item.selected = item.name === 'BTC'?true:false
				})
			}
			this.list     = _list;
			this.listItem = _list.filter(item => item.selected)[0];
			if(this.listItem.name === 'USDT' && this.uiEdit == 0 || this.listItem.name === 'USDT' && this.uiEdit == 1){
				//USDT初始值为100
				this.amount = 100;
			}else if(this.uiEdit == 2){
				//提现页面，初始值为空
				this.amount = '';
			}else{
				this.amount = this.listItem.floor;
			}
			this.setDefaultInMykey();
			this.getBalance(2)
		},
		getBalance(type){
			//在mykey中获取余额
			let self = this;
			if(this.isMYKEY && type==2){
				//拉取可能存在的EOS余额
				let _EOS = this.list.filter(item => item.name === 'EOS');
				if(_EOS.length > 0){
					util.fetch(util.ajaxUrl()+`/mykey/get-left`,{
						account:util.getStorage('EOSAccount'),
						token:this.token || util.getToken(),
					}).then(res => {
						if(res.retCode === 0){
							var arr = res.retData.data?res.retData.data.tokens.filter(item => item.symbol === 'EOS'):[];
							this.list.map(item => {
								if(item.name === 'EOS'){
									item.balance = arr.length > 0 ?arr[0].balance:0
								}
							})
						}else{
							Toast(res.retMsg || '未知错误')
						}
					}).catch(error => {
						console.log(error)
					})
				}

				let ETHAccount = util.getStorage('ETHAccount');
                if(ETHAccount){
                	//获取ETH余额
                	if (typeof web3 !== 'undefined') {
                		web3.eth.getBalance(ETHAccount, function (error, result) {
                			if(error){
                				setTimeout(()=>{
                    				self.getBalance(2)
                    			},1000)
                			}else{
                				result = web3.fromWei(result,'ether');
		                		self.list.map(item => {
		                			if(item.name === 'ETH'){
		                				item.balance = result
		                			}
		                		})
		                		if(self.listItem && self.listItem.name && self.listItem.name === 'ETH'){
		                			self.listItem.balance = result
		                		}
                			}
        				})
        				//获取代币余额
	                    var mtkAbi = [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}];
	                    Object.keys(util.addressAbi).forEach(name => {
	                    	var mtkContract = web3.eth.contract(mtkAbi).at(util.addressAbi[name]);
	                    	mtkContract.balanceOf(ETHAccount, function (error, result) {
	                    		if(error){
	                    			setTimeout(()=>{
	                    				self.getBalance(2)
	                    			},1000)
	                    		}else{
	                    			if(name === 'DAI'){
		                    			result = web3.fromWei(result,'ether');
		                    		}else if(name === 'USDT'){
		                    			result = web3.fromWei(result,'mwei');
		                    		}
		                    		//赋值内容
		                    		self.list.map(item => {
			                			if(item.name === name){
			                				item.balance = result
			                			}
			                		})
			                		if(self.listItem && self.listItem.name && self.listItem.name === name){
			                			self.listItem.balance = result
			                		}
	                    		}
	                    	});
	                    })
                	}
                }else{
                	//获取不到的时候，间隔一段时间再次拉取
                	if (typeof web3 !== 'undefined') {
                		web3.eth.getAccounts(function(error, accounts){
				            if(accounts && accounts[0]){
				                util.setStorage('ETHAccount',accounts[0]);
				            }else{
				            	setTimeout(() => {
				            		self.getBalance(type)
				            	},800)
				            }
				        })
                	}
                }
			}
		},
		isRealName(){
			if(this.realName === 0){
				//未认证
				this.$router.push('/goRealName')
			}else{
				//其他状态，直接跳转到认证结果状态
				this.$router.push('/realNameStatus')
			}
		},
		checkIsRealName(){
			//判断用户是否已实名认证
			return new Promise((resolve,reject) => {
				if(this.realName === 2){
					resolve()
				}else{
					reject()
				}
			})
		},
		sellAll(){
			//全部卖掉
			this.amount = this.listItem.balance;
			if(this.amount < this.listItem.floor){
				//小于最小单位
				this.calcMoney(this.amount)
			}else{
				this.getPrice(1)
			}
		},
		selectItem(item){
			//挑选币种
			if(this.uiEdit == 1 || this.uiEdit == 2) return
			this.list.map(ele => {
				ele.selected = item.name === ele.name?true:false;
				if(ele.selected){
					this.listItem = ele;
				}
			})
			if(this.listItem.name == 'BTC'){
				//BTC初始值为0.1
				this.amount = 0.1;
			}else if(this.listItem.name === 'USDT' && this.uiEdit == 0 || this.listItem.name === 'USDT' && this.uiEdit == 1){
				//USDT初始值为100
				this.amount = 100;
			}else{
				this.amount = this.listItem.floor;
			}
			this.setDefaultInMykey();
			this.getPrice(1);
		},
		setDefaultInMykey(){
			//在mykey中设置初始值
			if(this.isMYKEY){
				if(this.listItem.name === 'ETH'){
					this.amount = 1;
				}else if(this.listItem.name === 'DAI'){
					this.amount = 100;
				}else if(this.listItem.name === 'EOS'){
					this.amount = 100;
				}else if(this.listItem.name === 'USDT'){
					this.amount = 100;
				}else{
					this.amount = this.listItem.floor;
				}
			}
		},
		changeTradeStatus(status){
			//买入、售出状态切换
			if(this.uiEdit == 1){
				if(status === 2){
					util.callHandler('openUrl',{
						url: 'bbjApp://inOutCoin?type=in',     // 不带参数默认默认是选择充币
      					title: '充币',
      					needLogin: true
					})
					console.log('跳转到原生充币页面')
				}
				return
			}
			if(this.uiEdit == 2){
				if(status == 1){
					util.callHandler('openUrl',{
						url: 'bbjApp://inOutCoin?type=out',     // 不带参数默认默认是选择充币
      					title: '提币',
      					needLogin: true
					})
					console.log('跳转到原生提币页面')
				}
				return
			}
			this.tradeStatus = status;
			// this.amountOfMoney = '';
			if(this.listItem.name == 'BTC'){
				//BTC初始值为0.1
				this.amount = 0.1;
			}else if(this.listItem.name === 'USDT' && this.uiEdit == 0 || this.listItem.name === 'USDT' && this.uiEdit == 1){
				//USDT初始值为100
				this.amount = 100;
			}else{
				this.amount = this.listItem.floor;
			}
			this.setDefaultInMykey();
			this.getPrice(1);
		},
		goOrderList(){
			this.$router.push('/orderList')
		},
		goBack(){
			util.navigateBack(-1,this)
		},
		copyService(){
			//复制客服号
			this.$copyText(this.serverNumber).then(() => {
				Toast('复制成功')
			}).catch(() => {
				Toast('复制失败')
			})
		},
		amountSetFocus(){
			//点击整个框，数量输入框获取焦点
			this.$refs.input1.focus();
		},
		moneySetFocus(){
			//点击整个框，金额输入框获取焦点
			this.$refs.input2.focus();
		},
		stop(){return false},
		uploadTxid(){
			//重新提交可能存在的txid未提交情况
			let self = this;
			let uploadTxid = util.getStorage('uploadTxid');
			if(uploadTxid){
				uploadTxid = JSON.parse(uploadTxid);
				uploadTxid.token = this.token;
				this.uploadTimes++;
				util.fetch(util.ajaxUrl()+`/mykey/otc-outmoney`,uploadTxid).then(res => {
					if(res.retCode == 0){
						localStorage.removeItem('uploadTxid');
						Toast('重新提交成功')
					}else{
						Dialog.confirm({
							title: '由于网络原因',
							message: '您有一笔出售订单未提交成功',
							className:'sellType-dialog-index',
							cancelButtonColor:'#1989fa',
							confirmButtonText:'重新提交',
							showCancelButton:false,
							overlayClass:'sellType-mark-index'
						}).then(() => {
							if(self.uploadTimes < 2){
								self.uploadTxid();
							}else{
								Dialog.confirm({
									title: '出售订单创建失败',
									message: '请您联系客服微信：myotcservice07',
									className:'sellType-dialog',
									cancelButtonColor:'#1989fa',
									confirmButtonText:'确定',
									showCancelButton:false,
									overlayClass:'sellType-mark'
								}).then(() => {
									// self.mykeyOtcOutmoney(txid)
									console.log('confirm')
								})
								localStorage.removeItem('uploadTxid');
							}
							console.log('confirm')
						})
					}
				}).catch(error => {
					console.log(error)
				})
			}
		}
	},
	activated(){
		this.getBalance(2)
	},
	created() {
		//默认初始化tab
		this.tradeStatus = this.$route.query.tradeStatus || 1;
		//我的页面、合约K线、合约下单、猜涨跌的“充值”跳转到OTC（充值）页面
		if(this.$route.query.uiEdit){
			this.uiEdit = this.$route.query.uiEdit
		}
		if(this.$route.query.BTC) this.BTCFocus = true;
		sessionStorage.removeItem('pageState')
		// sessionStorage.removeItem('refresh')
		if(typeof this.tradeStatus === 'string') this.tradeStatus = Number(this.tradeStatus);
		util.waitSDKReady('index').then(token => {
			this.token = token;
			this.init();
			this.uploadTxid();
			setTimeout(() => {
				util.registerHandler('refreshCommonRequestWhenGoBackView',res => {
					this.init(1);
					util.callHandler('setStatusBarStyle',{
						style:'light'
					})
				})
				//退出登录的时候native调用H5方法清除token缓存
				util.registerHandler('loginOutDeleteToken',res => {
					window.token = '';
					this.token = '';
					localStorage.removeItem('token');
				})
				util.callHandler('setStatusBarStyle',{
					style:'light'
				})
			},500)
		}).catch((e) => {
			Toast('获取token失败')
		})
    }
}